home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / DJGPP / GAS211S2.ZIP / src / gas-211 / opcodes / i960-dis.c < prev    next >
C/C++ Source or Header  |  1993-05-30  |  20KB  |  835 lines

  1. /* Disassemble i80960 instructions.
  2.    Copyright (C) 1990, 1991 Free Software Foundation, Inc.
  3.  
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2, or (at your option)
  7. any later version.
  8.  
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. GNU General Public License for more details.
  13.  
  14. You should have received a copy of the GNU General Public License
  15. along with this program; see the file COPYING.  If not, write to
  16. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  17.  
  18. #include "dis-asm.h"
  19.  
  20. static char *reg_names[] = {
  21. /*  0 */    "pfp", "sp",  "rip", "r3",  "r4",  "r5",  "r6",  "r7", 
  22. /*  8 */    "r8",  "r9",  "r10", "r11", "r12", "r13", "r14", "r15",
  23. /* 16 */    "g0",  "g1",  "g2",  "g3",  "g4",  "g5",  "g6",  "g7", 
  24. /* 24 */    "g8",  "g9",  "g10", "g11", "g12", "g13", "g14", "fp", 
  25. /* 32 */    "pc",  "ac",  "ip",  "tc",  "fp0", "fp1", "fp2", "fp3" 
  26. };
  27.  
  28.  
  29. static FILE *stream;        /* Output goes here */
  30. static struct disassemble_info *info;
  31. static void print_addr();
  32. static void ctrl();
  33. static void cobr();
  34. static void reg();
  35. static int mem();
  36. static void ea();
  37. static void dstop();
  38. static void regop();
  39. static void invalid();
  40. static int pinsn();
  41. static void put_abs();
  42.  
  43.  
  44. /* Print the i960 instruction at address 'memaddr' in debugged memory,
  45.  * on stream 's'.  Returns length of the instruction, in bytes.
  46.  */
  47. int
  48. print_insn_i960 (memaddr, info_arg)
  49.     bfd_vma memaddr;
  50.     struct disassemble_info *info_arg;
  51. {
  52.   unsigned int word1, word2;
  53.   char buffer[8];
  54.   info = info_arg;
  55.   stream = info->stream;
  56.  
  57.   /* FIXME, should only read as much of this as we actually need to
  58.      disassemble.  word1 might be the last word of a section.  */
  59.   {
  60.     int status =
  61.       (*info->read_memory_func) (memaddr, (bfd_byte *) buffer, 8, info);
  62.     if (status != 0)
  63.       {
  64.     (*info->memory_error_func) (status, memaddr, info);
  65.     return -1;
  66.       }
  67.   }
  68.  
  69.   word1 =buffer [0] |( buffer[1]<< 8) | (buffer[2] << 16) | ( buffer[3] <<24);
  70.   word2 =buffer [4] |( buffer[5]<< 8) | (buffer[6] << 16) | ( buffer[7] <<24);
  71.   return pinsn( memaddr, word1, word2 );
  72. }
  73.  
  74. #define IN_GDB
  75.  
  76. /*****************************************************************************
  77.  *    All code below this point should be identical with that of
  78.  *    the disassembler in gdmp960.
  79.  
  80.  A noble sentiment, but at least in cosmetic ways (info->fprintf_func), it
  81.  just ain't so. -kingdon, 31 Mar 93
  82.  *****************************************************************************/
  83.  
  84. struct tabent {
  85.     char    *name;
  86.     char    numops;
  87. };
  88.  
  89. static int
  90. pinsn( memaddr, word1, word2 )
  91.     unsigned long memaddr;
  92.     unsigned long word1, word2;
  93. {
  94.     int instr_len;
  95.  
  96.     instr_len = 4;
  97.     put_abs( word1, word2 );
  98.  
  99.     /* Divide instruction set into classes based on high 4 bits of opcode*/
  100.     switch ( (word1 >> 28) & 0xf ){
  101.     case 0x0:
  102.     case 0x1:
  103.         ctrl( memaddr, word1, word2 );
  104.         break;
  105.     case 0x2:
  106.     case 0x3:
  107.         cobr( memaddr, word1, word2 );
  108.         break;
  109.     case 0x5:
  110.     case 0x6:
  111.     case 0x7:
  112.         reg( word1 );
  113.         break;
  114.     case 0x8:
  115.     case 0x9:
  116.     case 0xa:
  117.     case 0xb:
  118.     case 0xc:
  119.         instr_len = mem( memaddr, word1, word2, 0 );
  120.         break;
  121.     default:
  122.         /* invalid instruction, print as data word */ 
  123.         invalid( word1 );
  124.         break;
  125.     }
  126.     return instr_len;
  127. }
  128.  
  129. /****************************************/
  130. /* CTRL format                */
  131. /****************************************/
  132. static void
  133. ctrl( memaddr, word1, word2 )
  134.     unsigned long memaddr;
  135.     unsigned long word1, word2;
  136. {
  137.     int i;
  138.     static struct tabent ctrl_tab[] = {
  139.         NULL,        0,    /* 0x00 */
  140.         NULL,        0,    /* 0x01 */
  141.         NULL,        0,    /* 0x02 */
  142.         NULL,        0,    /* 0x03 */
  143.         NULL,        0,    /* 0x04 */
  144.         NULL,        0,    /* 0x05 */
  145.         NULL,        0,    /* 0x06 */
  146.         NULL,        0,    /* 0x07 */
  147.         "b",        1,    /* 0x08 */
  148.         "call",        1,    /* 0x09 */
  149.         "ret",        0,    /* 0x0a */
  150.         "bal",        1,    /* 0x0b */
  151.         NULL,        0,    /* 0x0c */
  152.         NULL,        0,    /* 0x0d */
  153.         NULL,        0,    /* 0x0e */
  154.         NULL,        0,    /* 0x0f */
  155.         "bno",        1,    /* 0x10 */
  156.         "bg",        1,    /* 0x11 */
  157.         "be",        1,    /* 0x12 */
  158.         "bge",        1,    /* 0x13 */
  159.         "bl",        1,    /* 0x14 */
  160.         "bne",        1,    /* 0x15 */
  161.         "ble",        1,    /* 0x16 */
  162.         "bo",        1,    /* 0x17 */
  163.         "faultno",    0,    /* 0x18 */
  164.         "faultg",    0,    /* 0x19 */
  165.         "faulte",    0,    /* 0x1a */
  166.         "faultge",    0,    /* 0x1b */
  167.         "faultl",    0,    /* 0x1c */
  168.         "faultne",    0,    /* 0x1d */
  169.         "faultle",    0,    /* 0x1e */
  170.         "faulto",    0,    /* 0x1f */
  171.     };
  172.  
  173.     i = (word1 >> 24) & 0xff;
  174.     if ( (ctrl_tab[i].name == NULL) || ((word1 & 1) != 0) ){
  175.         invalid( word1 );
  176.         return;
  177.     }
  178.  
  179.     (*info->fprintf_func) ( stream, ctrl_tab[i].name );
  180.     if ( word1 & 2 ){        /* Predicts branch not taken */
  181.         (*info->fprintf_func) ( stream, ".f" );
  182.     }
  183.  
  184.     if ( ctrl_tab[i].numops == 1 ){
  185.         /* EXTRACT DISPLACEMENT AND CONVERT TO ADDRESS */
  186.         word1 &= 0x00ffffff;
  187.         if ( word1 & 0x00800000 ){        /* Sign bit is set */
  188.             word1 |= (-1 & ~0xffffff);    /* Sign extend */
  189.         }
  190.         (*info->fprintf_func)( stream, "\t" );
  191.         print_addr( word1 + memaddr );
  192.     }
  193. }
  194.  
  195. /****************************************/
  196. /* COBR format                */
  197. /****************************************/
  198. static void
  199. cobr( memaddr, word1, word2 )
  200.     unsigned long memaddr;
  201.     unsigned long word1, word2;
  202. {
  203.     int src1;
  204.     int src2;
  205.     int i;
  206.  
  207.     static struct tabent cobr_tab[] = {
  208.         "testno",    1,    /* 0x20 */
  209.         "testg",    1,    /* 0x21 */
  210.         "teste",    1,    /* 0x22 */
  211.         "testge",    1,    /* 0x23 */
  212.         "testl",    1,    /* 0x24 */
  213.         "testne",    1,    /* 0x25 */
  214.         "testle",    1,    /* 0x26 */
  215.         "testo",    1,    /* 0x27 */
  216.         NULL,        0,    /* 0x28 */
  217.         NULL,        0,    /* 0x29 */
  218.         NULL,        0,    /* 0x2a */
  219.         NULL,        0,    /* 0x2b */
  220.         NULL,        0,    /* 0x2c */
  221.         NULL,        0,    /* 0x2d */
  222.         NULL,        0,    /* 0x2e */
  223.         NULL,        0,    /* 0x2f */
  224.         "bbc",        3,    /* 0x30 */
  225.         "cmpobg",    3,    /* 0x31 */
  226.         "cmpobe",    3,    /* 0x32 */
  227.         "cmpobge",    3,    /* 0x33 */
  228.         "cmpobl",    3,    /* 0x34 */
  229.         "cmpobne",    3,    /* 0x35 */
  230.         "cmpoble",    3,    /* 0x36 */
  231.         "bbs",        3,    /* 0x37 */
  232.         "cmpibno",    3,    /* 0x38 */
  233.         "cmpibg",    3,    /* 0x39 */
  234.         "cmpibe",    3,    /* 0x3a */
  235.         "cmpibge",    3,    /* 0x3b */
  236.         "cmpibl",    3,    /* 0x3c */
  237.         "cmpibne",    3,    /* 0x3d */
  238.         "cmpible",    3,    /* 0x3e */
  239.         "cmpibo",    3,    /* 0x3f */
  240.     };
  241.  
  242.     i = ((word1 >> 24) & 0xff) - 0x20;
  243.     if ( cobr_tab[i].name == NULL ){
  244.         invalid( word1 );
  245.         return;
  246.     }
  247.  
  248.     (*info->fprintf_func) ( stream, cobr_tab[i].name );
  249.     if ( word1 & 2 ){        /* Predicts branch not taken */
  250.         (*info->fprintf_func) ( stream, ".f" );
  251.     }
  252.     (*info->fprintf_func)( stream, "\t" );
  253.  
  254.     src1 = (word1 >> 19) & 0x1f;
  255.     src2 = (word1 >> 14) & 0x1f;
  256.  
  257.     if ( word1 & 0x02000 ){        /* M1 is 1 */
  258.         (*info->fprintf_func)( stream, "%d", src1 );
  259.     } else {            /* M1 is 0 */
  260.         (*info->fprintf_func)( stream, reg_names[src1] );
  261.     }
  262.  
  263.     if ( cobr_tab[i].numops > 1 ){
  264.         if ( word1 & 1 ){        /* S2 is 1 */
  265.             (*info->fprintf_func)( stream, ",sf%d,", src2 );
  266.         } else {            /* S1 is 0 */
  267.             (*info->fprintf_func)( stream, ",%s,", reg_names[src2] );
  268.         }
  269.  
  270.         /* Extract displacement and convert to address
  271.          */
  272.         word1 &= 0x00001ffc;
  273.         if ( word1 & 0x00001000 ){    /* Negative displacement */
  274.             word1 |= (-1 & ~0x1fff);    /* Sign extend */
  275.         }
  276.         print_addr( memaddr + word1 );
  277.     }
  278. }
  279.  
  280. /****************************************/
  281. /* MEM format                */
  282. /****************************************/
  283. static int                /* returns instruction length: 4 or 8 */
  284. mem( memaddr, word1, word2, noprint )
  285.     unsigned long memaddr;
  286.     unsigned long word1, word2;
  287.     int noprint;        /* If TRUE, return instruction length, but
  288.                  * don't output any text.
  289.                  */
  290. {
  291.     int i, j;
  292.     int len;
  293.     int mode;
  294.     int offset;
  295.     char *reg1, *reg2, *reg3;
  296.  
  297.     /* This lookup table is too sparse to make it worth typing in, but not
  298.      * so large as to make a sparse array necessary.  We allocate the
  299.      * table at runtime, initialize all entries to empty, and copy the
  300.      * real ones in from an initialization table.
  301.      *
  302.      * NOTE: In this table, the meaning of 'numops' is:
  303.      *     1: single operand
  304.      *     2: 2 operands, load instruction
  305.      *    -2: 2 operands, store instruction
  306.      */
  307.     static struct tabent *mem_tab = NULL;
  308. /* Opcodes of 0x8X, 9X, aX, bX, and cX must be in the table.  */
  309. #define MEM_MIN    0x80
  310. #define MEM_MAX    0xcf
  311. #define MEM_SIZ    ((MEM_MAX-MEM_MIN+1) * sizeof(struct tabent))
  312.  
  313.     static struct { int opcode; char *name; char numops; } mem_init[] = {
  314.         0x80,    "ldob",     2,
  315.         0x82,    "stob",    -2,
  316.         0x84,    "bx",     1,
  317.         0x85,    "balx",     2,
  318.         0x86,    "callx", 1,
  319.         0x88,    "ldos",     2,
  320.         0x8a,    "stos",    -2,
  321.         0x8c,    "lda",     2,
  322.         0x90,    "ld",     2,
  323.         0x92,    "st",    -2,
  324.         0x98,    "ldl",     2,
  325.         0x9a,    "stl",    -2,
  326.         0xa0,    "ldt",     2,
  327.         0xa2,    "stt",    -2,
  328.         0xb0,    "ldq",     2,
  329.         0xb2,    "stq",    -2,
  330.         0xc0,    "ldib",     2,
  331.         0xc2,    "stib",    -2,
  332.         0xc8,    "ldis",     2,
  333.         0xca,    "stis",    -2,
  334.         0,    NULL,    0
  335.     };
  336.  
  337.     if ( mem_tab == NULL ){
  338.         mem_tab = (struct tabent *) xmalloc( MEM_SIZ );
  339.         memset( (void *) mem_tab, 0, MEM_SIZ );
  340.         for ( i = 0; mem_init[i].opcode != 0; i++ ){
  341.             j = mem_init[i].opcode - MEM_MIN;
  342.             mem_tab[j].name = mem_init[i].name;
  343.             mem_tab[j].numops = mem_init[i].numops;
  344.         }
  345.     }
  346.  
  347.     i = ((word1 >> 24) & 0xff) - MEM_MIN;
  348.     mode = (word1 >> 10) & 0xf;
  349.  
  350.     if ( (mem_tab[i].name != NULL)        /* Valid instruction */
  351.     &&   ((mode == 5) || (mode >=12)) ){    /* With 32-bit displacement */
  352.         len = 8;
  353.     } else {
  354.         len = 4;
  355.     }
  356.  
  357.     if ( noprint ){
  358.         return len;
  359.     }
  360.  
  361.     if ( (mem_tab[i].name == NULL) || (mode == 6) ){
  362.         invalid( word1 );
  363.         return len;
  364.     }
  365.  
  366.     (*info->fprintf_func)( stream, "%s\t", mem_tab[i].name );
  367.  
  368.     reg1 = reg_names[ (word1 >> 19) & 0x1f ];    /* MEMB only */
  369.     reg2 = reg_names[ (word1 >> 14) & 0x1f ];
  370.     reg3 = reg_names[ word1 & 0x1f ];        /* MEMB only */
  371.     offset = word1 & 0xfff;                /* MEMA only  */
  372.  
  373.     switch ( mem_tab[i].numops ){
  374.  
  375.     case 2: /* LOAD INSTRUCTION */
  376.         if ( mode & 4 ){            /* MEMB FORMAT */
  377.             ea( memaddr, mode, reg2, reg3, word1, word2 );
  378.             (*info->fprintf_func)( stream, ",%s", reg1 );
  379.         } else {                /* MEMA FORMAT */
  380.             (*info->fprintf_func)( stream, "0x%x", (unsigned) offset );
  381.             if (mode & 8) {
  382.                 (*info->fprintf_func)( stream, "(%s)", reg2 );
  383.             }
  384.             (*info->fprintf_func)( stream, ",%s", reg1 );
  385.         }
  386.         break;
  387.  
  388.     case -2: /* STORE INSTRUCTION */
  389.         if ( mode & 4 ){            /* MEMB FORMAT */
  390.             (*info->fprintf_func)( stream, "%s,", reg1 );
  391.             ea( memaddr, mode, reg2, reg3, word1, word2 );
  392.         } else {                /* MEMA FORMAT */
  393.             (*info->fprintf_func)( stream, "%s,0x%x", reg1, (unsigned) offset );
  394.             if (mode & 8) {
  395.                 (*info->fprintf_func)( stream, "(%s)", reg2 );
  396.             }
  397.         }
  398.         break;
  399.  
  400.     case 1: /* BX/CALLX INSTRUCTION */
  401.         if ( mode & 4 ){            /* MEMB FORMAT */
  402.             ea( memaddr, mode, reg2, reg3, word1, word2 );
  403.         } else {                /* MEMA FORMAT */
  404.             (*info->fprintf_func)( stream, "0x%x", (unsigned) offset );
  405.             if (mode & 8) {
  406.                 (*info->fprintf_func)( stream, "(%s)", reg2 );
  407.             }
  408.         }
  409.         break;
  410.     }
  411.  
  412.     return len;
  413. }
  414.  
  415. /****************************************/
  416. /* REG format                */
  417. /****************************************/
  418. static void
  419. reg( word1 )
  420.     unsigned long word1;
  421. {
  422.     int i, j;
  423.     int opcode;
  424.     int fp;
  425.     int m1, m2, m3;
  426.     int s1, s2;
  427.     int src, src2, dst;
  428.     char *mnemp;
  429.  
  430.     /* This lookup table is too sparse to make it worth typing in, but not
  431.      * so large as to make a sparse array necessary.  We allocate the
  432.      * table at runtime, initialize all entries to empty, and copy the
  433.      * real ones in from an initialization table.
  434.      *
  435.      * NOTE: In this table, the meaning of 'numops' is:
  436.      *     1: single operand, which is NOT a destination.
  437.      *    -1: single operand, which IS a destination.
  438.      *     2: 2 operands, the 2nd of which is NOT a destination.
  439.      *    -2: 2 operands, the 2nd of which IS a destination.
  440.      *     3: 3 operands
  441.      *
  442.      *    If an opcode mnemonic begins with "F", it is a floating-point
  443.      *    opcode (the "F" is not printed).
  444.      */
  445.  
  446.     static struct tabent *reg_tab = NULL;
  447.     static struct { int opcode; char *name; char numops; } reg_init[] = {
  448. #define REG_MIN    0x580
  449.         0x580,    "notbit",    3,
  450.         0x581,    "and",        3,
  451.         0x582,    "andnot",    3,
  452.         0x583,    "setbit",    3,
  453.         0x584,    "notand",    3,
  454.         0x586,    "xor",        3,
  455.         0x587,    "or",        3,
  456.         0x588,    "nor",        3,
  457.         0x589,    "xnor",        3,
  458.         0x58a,    "not",        -2,
  459.         0x58b,    "ornot",    3,
  460.         0x58c,    "clrbit",    3,
  461.         0x58d,    "notor",    3,
  462.         0x58e,    "nand",        3,
  463.         0x58f,    "alterbit",    3,
  464.         0x590,     "addo",        3,
  465.         0x591,     "addi",        3,
  466.         0x592,     "subo",        3,
  467.         0x593,     "subi",        3,
  468.         0x598,     "shro",        3,
  469.         0x59a,     "shrdi",    3,
  470.         0x59b,     "shri",        3,
  471.         0x59c,     "shlo",        3,
  472.         0x59d,     "rotate",    3,
  473.         0x59e,     "shli",        3,
  474.         0x5a0,     "cmpo",        2,
  475.         0x5a1,     "cmpi",        2,
  476.         0x5a2,     "concmpo",    2,
  477.         0x5a3,     "concmpi",    2,
  478.         0x5a4,     "cmpinco",    3,
  479.         0x5a5,     "cmpinci",    3,
  480.         0x5a6,     "cmpdeco",    3,
  481.         0x5a7,     "cmpdeci",    3,
  482.         0x5ac,     "scanbyte",    2,
  483.         0x5ae,     "chkbit",    2,
  484.         0x5b0,     "addc",        3,
  485.         0x5b2,     "subc",        3,
  486.         0x5cc,    "mov",        -2,
  487.         0x5d8,    "eshro",    3,
  488.         0x5dc,    "movl",        -2,
  489.         0x5ec,    "movt",        -2,
  490.         0x5fc,    "movq",        -2,
  491.         0x600,    "synmov",    2,
  492.         0x601,    "synmovl",    2,
  493.         0x602,    "synmovq",    2,
  494.         0x603,    "cmpstr",    3,
  495.         0x604,    "movqstr",    3,
  496.         0x605,    "movstr",    3,
  497.         0x610,    "atmod",    3,
  498.         0x612,    "atadd",    3,
  499.         0x613,    "inspacc",    -2,
  500.         0x614,    "ldphy",    -2,
  501.         0x615,    "synld",    -2,
  502.         0x617,    "fill",        3,
  503.         0x630,    "sdma",        3,
  504.         0x631,    "udma",        0,
  505.         0x640,    "spanbit",    -2,
  506.         0x641,    "scanbit",    -2,
  507.         0x642,    "daddc",    3,
  508.         0x643,    "dsubc",    3,
  509.         0x644,    "dmovt",    -2,
  510.         0x645,    "modac",    3,
  511.         0x646,    "condrec",    -2,
  512.         0x650,    "modify",    3,
  513.         0x651,    "extract",    3,
  514.         0x654,    "modtc",    3,
  515.         0x655,    "modpc",    3,
  516.         0x656,    "receive",    -2,
  517.         0x659,    "sysctl",    3,
  518.         0x660,    "calls",    1,
  519.         0x662,    "send",        3,
  520.         0x663,    "sendserv",    1,
  521.         0x664,    "resumprcs",    1,
  522.         0x665,    "schedprcs",    1,
  523.         0x666,    "saveprcs",    0,
  524.         0x668,    "condwait",    1,
  525.         0x669,    "wait",        1,
  526.         0x66a,    "signal",    1,
  527.         0x66b,    "mark",        0,
  528.         0x66c,    "fmark",    0,
  529.         0x66d,    "flushreg",    0,
  530.         0x66f,    "syncf",    0,
  531.         0x670,    "emul",        3,
  532.         0x671,    "ediv",        3,
  533.         0x673,     "ldtime",    -1,
  534.         0x674,    "Fcvtir",    -2,
  535.         0x675,    "Fcvtilr",    -2,
  536.         0x676,    "Fscalerl",    3,
  537.         0x677,    "Fscaler",    3,
  538.         0x680,    "Fatanr",    3,
  539.         0x681,    "Flogepr",    3,
  540.         0x682,    "Flogr",    3,
  541.         0x683,    "Fremr",    3,
  542.         0x684,    "Fcmpor",    2,
  543.         0x685,    "Fcmpr",    2,
  544.         0x688,    "Fsqrtr",    -2,
  545.         0x689,    "Fexpr",    -2,
  546.         0x68a,    "Flogbnr",    -2,
  547.         0x68b,    "Froundr",    -2,
  548.         0x68c,    "Fsinr",    -2,
  549.         0x68d,    "Fcosr",    -2,
  550.         0x68e,    "Ftanr",    -2,
  551.         0x68f,    "Fclassr",    1,
  552.         0x690,    "Fatanrl",    3,
  553.         0x691,    "Flogeprl",    3,
  554.         0x692,    "Flogrl",    3,
  555.         0x693,    "Fremrl",    3,
  556.         0x694,    "Fcmporl",    2,
  557.         0x695,    "Fcmprl",    2,
  558.         0x698,    "Fsqrtrl",    -2,
  559.         0x699,    "Fexprl",    -2,
  560.         0x69a,    "Flogbnrl",    -2,
  561.         0x69b,    "Froundrl",    -2,
  562.         0x69c,    "Fsinrl",    -2,
  563.         0x69d,    "Fcosrl",    -2,
  564.         0x69e,    "Ftanrl",    -2,
  565.         0x69f,    "Fclassrl",    1,
  566.         0x6c0,    "Fcvtri",    -2,
  567.         0x6c1,    "Fcvtril",    -2,
  568.         0x6c2,    "Fcvtzri",    -2,
  569.         0x6c3,    "Fcvtzril",    -2,
  570.         0x6c9,    "Fmovr",    -2,
  571.         0x6d9,    "Fmovrl",    -2,
  572.         0x6e1,     "Fmovre",    -2,
  573.         0x6e2,     "Fcpysre",    3,
  574.         0x6e3,     "Fcpyrsre",    3,
  575.         0x701,    "mulo",        3,
  576.         0x708,    "remo",        3,
  577.         0x70b,    "divo",        3,
  578.         0x741,    "muli",        3,
  579.         0x748,    "remi",        3,
  580.         0x749,    "modi",        3,
  581.         0x74b,    "divi",        3,
  582.         0x78b,    "Fdivr",    3,
  583.         0x78c,    "Fmulr",    3,
  584.         0x78d,    "Fsubr",    3,
  585.         0x78f,    "Faddr",    3,
  586.         0x79b,    "Fdivrl",    3,
  587.         0x79c,    "Fmulrl",    3,
  588.         0x79d,    "Fsubrl",    3,
  589.         0x79f,    "Faddrl",    3,
  590. #define REG_MAX    0x79f
  591. #define REG_SIZ    ((REG_MAX-REG_MIN+1) * sizeof(struct tabent))
  592.         0,    NULL,    0
  593.     };
  594.  
  595.     if ( reg_tab == NULL ){
  596.         reg_tab = (struct tabent *) xmalloc( REG_SIZ );
  597.         memset( (void *) reg_tab, 0, REG_SIZ );
  598.         for ( i = 0; reg_init[i].opcode != 0; i++ ){
  599.             j = reg_init[i].opcode - REG_MIN;
  600.             reg_tab[j].name = reg_init[i].name;
  601.             reg_tab[j].numops = reg_init[i].numops;
  602.         }
  603.     }
  604.  
  605.     opcode = ((word1 >> 20) & 0xff0) | ((word1 >> 7) & 0xf);
  606.     i = opcode - REG_MIN;
  607.  
  608.     if ( (opcode<REG_MIN) || (opcode>REG_MAX) || (reg_tab[i].name==NULL) ){
  609.         invalid( word1 );
  610.         return;
  611.     }
  612.  
  613.     mnemp = reg_tab[i].name;
  614.     if ( *mnemp == 'F' ){
  615.         fp = 1;
  616.         mnemp++;
  617.     } else {
  618.         fp = 0;
  619.     }
  620.  
  621.     (*info->fprintf_func)( stream, mnemp );
  622.  
  623.     s1   = (word1 >> 5)  & 1;
  624.     s2   = (word1 >> 6)  & 1;
  625.     m1   = (word1 >> 11) & 1;
  626.     m2   = (word1 >> 12) & 1;
  627.     m3   = (word1 >> 13) & 1;
  628.     src  =  word1        & 0x1f;
  629.     src2 = (word1 >> 14) & 0x1f;
  630.     dst  = (word1 >> 19) & 0x1f;
  631.  
  632.     if  ( reg_tab[i].numops != 0 ){
  633.         (*info->fprintf_func)( stream, "\t" );
  634.  
  635.         switch ( reg_tab[i].numops ){
  636.         case 1:
  637.             regop( m1, s1, src, fp );
  638.             break;
  639.         case -1:
  640.             dstop( m3, dst, fp );
  641.             break;
  642.         case 2:
  643.             regop( m1, s1, src, fp );
  644.             (*info->fprintf_func)( stream, "," );
  645.             regop( m2, s2, src2, fp );
  646.             break;
  647.         case -2:
  648.             regop( m1, s1, src, fp );
  649.             (*info->fprintf_func)( stream, "," );
  650.             dstop( m3, dst, fp );
  651.             break;
  652.         case 3:
  653.             regop( m1, s1, src, fp );
  654.             (*info->fprintf_func)( stream, "," );
  655.             regop( m2, s2, src2, fp );
  656.             (*info->fprintf_func)( stream, "," );
  657.             dstop( m3, dst, fp );
  658.             break;
  659.         }
  660.     }
  661. }
  662.  
  663.  
  664. /*
  665.  * Print out effective address for memb instructions.
  666.  */
  667. static void
  668. ea( memaddr, mode, reg2, reg3, word1, word2 )
  669.     unsigned long memaddr;
  670.     int mode;
  671.     char *reg2, *reg3;
  672. int word1;
  673.     unsigned int word2;
  674. {
  675.     int scale;
  676.     static int scale_tab[] = { 1, 2, 4, 8, 16 };
  677.  
  678.     scale = (word1 >> 7) & 0x07;
  679.     if ( (scale > 4) || ((word1 >> 5) & 0x03 != 0) ){
  680.         invalid( word1 );
  681.         return;
  682.     }
  683.     scale = scale_tab[scale];
  684.  
  685.     switch (mode) {
  686.     case 4:                         /* (reg) */
  687.         (*info->fprintf_func)( stream, "(%s)", reg2 );
  688.         break;
  689.     case 5:                        /* displ+8(ip) */
  690.         print_addr( word2+8+memaddr );
  691.         break;
  692.     case 7:                        /* (reg)[index*scale] */
  693.         if (scale == 1) {
  694.             (*info->fprintf_func)( stream, "(%s)[%s]", reg2, reg3 );
  695.         } else {
  696.             (*info->fprintf_func)( stream, "(%s)[%s*%d]",reg2,reg3,scale);
  697.         }
  698.         break;
  699.     case 12:                    /* displacement */
  700.         print_addr( word2 );
  701.         break;
  702.     case 13:                    /* displ(reg) */
  703.         print_addr( word2 );
  704.         (*info->fprintf_func)( stream, "(%s)", reg2 );
  705.         break;
  706.     case 14:                    /* displ[index*scale] */
  707.         print_addr( word2 );
  708.         if (scale == 1) {
  709.             (*info->fprintf_func)( stream, "[%s]", reg3 );
  710.         } else {
  711.             (*info->fprintf_func)( stream, "[%s*%d]", reg3, scale );
  712.         }
  713.         break;
  714.     case 15:                /* displ(reg)[index*scale] */
  715.         print_addr( word2 );
  716.         if (scale == 1) {
  717.             (*info->fprintf_func)( stream, "(%s)[%s]", reg2, reg3 );
  718.         } else {
  719.             (*info->fprintf_func)( stream, "(%s)[%s*%d]",reg2,reg3,scale );
  720.         }
  721.         break;
  722.     default:
  723.         invalid( word1 );
  724.         return;
  725.     }
  726. }
  727.  
  728.  
  729. /************************************************/
  730. /* Register Instruction Operand          */
  731. /************************************************/
  732. static void
  733. regop( mode, spec, reg, fp )
  734.     int mode, spec, reg, fp;
  735. {
  736.     if ( fp ){                /* FLOATING POINT INSTRUCTION */
  737.         if ( mode == 1 ){            /* FP operand */
  738.             switch ( reg ){
  739.             case 0:  (*info->fprintf_func)( stream, "fp0" );
  740.               break;
  741.             case 1:  (*info->fprintf_func)( stream, "fp1" );
  742.               break;
  743.             case 2:  (*info->fprintf_func)( stream, "fp2" );
  744.               break;
  745.             case 3:  (*info->fprintf_func)( stream, "fp3" );
  746.               break;
  747.             case 16: (*info->fprintf_func)( stream, "0f0.0" );
  748.               break;
  749.             case 22: (*info->fprintf_func)( stream, "0f1.0" );
  750.               break;
  751.             default: (*info->fprintf_func)( stream, "?" );
  752.               break;
  753.             }
  754.         } else {                /* Non-FP register */
  755.             (*info->fprintf_func)( stream, reg_names[reg] );
  756.         }
  757.     } else {                /* NOT FLOATING POINT */
  758.         if ( mode == 1 ){            /* Literal */
  759.             (*info->fprintf_func)( stream, "%d", reg );
  760.         } else {                /* Register */
  761.             if ( spec == 0 ){
  762.                 (*info->fprintf_func)( stream, reg_names[reg] );
  763.             } else {
  764.                 (*info->fprintf_func)( stream, "sf%d", reg );
  765.             }
  766.         }
  767.     }
  768. }
  769.  
  770. /************************************************/
  771. /* Register Instruction Destination Operand    */
  772. /************************************************/
  773. static void
  774. dstop( mode, reg, fp )
  775.     int mode, reg, fp;
  776. {
  777.     /* 'dst' operand can't be a literal. On non-FP instructions,  register
  778.      * mode is assumed and "m3" acts as if were "s3";  on FP-instructions,
  779.      * sf registers are not allowed so m3 acts normally.
  780.      */
  781.      if ( fp ){
  782.         regop( mode, 0, reg, fp );
  783.      } else {
  784.         regop( 0, mode, reg, fp );
  785.      }
  786. }
  787.  
  788.  
  789. static void
  790. invalid( word1 )
  791.     int word1;
  792. {
  793.     (*info->fprintf_func)( stream, ".word\t0x%08x", (unsigned) word1 );
  794. }    
  795.  
  796. static void
  797. print_addr(a)
  798. int a;
  799. {
  800.   (*info->print_address_func) ((bfd_vma) a, info);
  801. }
  802.  
  803. static void
  804. put_abs( word1, word2 )
  805.     unsigned long word1, word2;
  806. {
  807. #ifdef IN_GDB
  808.     return;
  809. #else
  810.     int len;
  811.  
  812.     switch ( (word1 >> 28) & 0xf ){
  813.     case 0x8:
  814.     case 0x9:
  815.     case 0xa:
  816.     case 0xb:
  817.     case 0xc:
  818.         /* MEM format instruction */
  819.         len = mem( 0, word1, word2, 1 );
  820.         break;
  821.     default:
  822.         len = 4;
  823.         break;
  824.     }
  825.  
  826.     if ( len == 8 ){
  827.         (*info->fprintf_func)( stream, "%08x %08x\t", word1, word2 );
  828.     } else {
  829.         (*info->fprintf_func)( stream, "%08x         \t", word1 );
  830.     }
  831. ;
  832.  
  833. #endif
  834. }
  835.